<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/css/layui.css}" rel="stylesheet" />
<link th:href="@{/css/base.css}" rel="stylesheet" />
<link th:href="@{/css/home.css}" rel="stylesheet" />

<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-jiugonggePrizes-add" name="form-jiugonggePrizes-add">
		<div class="aui-form-group clear">
				<label class="aui-label-control">
					奖品名称： <em>*</em>
				</label>
				<div class="aui-form-input">
					<input type="text" class="aui-form-control-two" name="name" id="name"  onBlur="checkna()" required  placeholder="请输入奖品名称">
					<span class="tips" id="divname">长度1~6个字符</span>
				</div>
			</div>
			<div class="aui-form-group clear">
				<label class="aui-label-control">
					奖品图片 <em>*</em>
				</label>
				<div class="aui-form-input">
					<div class="aui-content-img-box aui-content-full">
						<div class="aui-photo aui-up-img clear">
							<section class="aui-file-up fl" id="test1">
								<img src="/img/up.png" class="add-img" id="demo1" name="demo1">
								<input name="img" id="img" type="hidden" class="file">
							</section>
							<span class="tips" id="picname">小于5M</span>
						</div>
					</div>
				</div>
			</div>		
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/layui/layui.js}"></script>
	<!-- <script th:src="@{/js/up.js}"></script>  -->
	
	<script th:inline="javascript">
		var prefix = ctx + "jiugongge/jiugonggePrizes"	
		$("#form-jiugonggePrizes-add").validate({
			rules : {
				name : {
					required : true,
				},

			},
			messages : {
				"name" : {
					required : "",
				},
			}
		});
		
		function submitHandler() {
			 if ($.validate.form()) {
				     var img = document.getElementById("img").value
					 if(img === null || '' === img || img === undefined){
						layer.msg('图片正在上传或请上传奖品图片');
					 }else{
						 $.operate.save(prefix + "/add", $('#form-jiugonggePrizes-add').serialize()); 
					 }
					 
					
			 }	
		}
		
			
		//验证姓名
		function checkna(){
		    var na= $("#name").val();
			if( na.length <1 || na.length >6){
				divname.innerHTML='<font class="tips_false">长度是1~6个字符</font>';
			}else{
				divname.innerHTML='<font class="tips_true">输入正确</font>';
			}

		}
		
		//验证姓名
		function checkimg(){
		   

		}
		

	 	 layui.use('upload',function() {
							var $ = layui.jquery, upload = layui.upload;
                            //普通图片上传
							var uploadInst = upload.render({
										elem : '#test1',
										url : ctx + 'system/storage/upload',
										before : function(obj) {
											//预读本地文件示例，不支持ie8
											obj.preview(function(index,file, result) {
														$('#demo1').attr('src',result); //图片链接（base64）
													});
										},
										done : function(res) {
											//如果上传失败
											if (res.code > 0) {
												return layer.msg('上传失败');
											}
												var imgContainer = $(this).parents(".aui-photo");
												layer.msg('上传成功');
											//上传成功
										},
										error : function() {
											//演示失败状态，并实现重传
											var demoText = $('#picname');
											demoText.html('<font class="tips_false">请上传奖品图片</font>');
											demoText.find('.demo-reload').on(
													'click', function() {
														uploadInst.upload();
													});
										}
									});
						});

	
	</script>
</body>
</html>
